package bairui.international.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lianjing.sh.project.common.service.Service_Number;
import com.sh_lianjing.state.StateTransition;

import bairui.international.model.domain.jpa.TB_BranchCompanyStaff;
import bairui.international.model.domain.jpa.TB_BranchCompanyStaffWithdrawOrder;
import bairui.international.model.status.State_BranchCompanyStaffWithdrawOrder;
import bairui.international.service.Service_BranchCompanyStaffMoneyRecord;
import bairui.international.service.Service_BranchCompanyStaffWithdrawOrder;
import bairui.international.service.Service_BranchCompanyStaffWithdrawVerifyRecord;

/**
 * 
 * 【(分公司员工提现单)TB_BranchCompanyStaffWithdrawOrder】服务实现
 *
 * @generated
 * 
 * @see bairui.international.model.domain.jpa.TB_BranchCompanyStaffWithdrawOrder 模型
 * @see Service_BranchCompanyStaffWithdrawOrder 服务接口
 * @see BService_BranchCompanyStaffWithdrawOrderImpl 服务实现基础
 *
 */
@Service
public class Service_BranchCompanyStaffWithdrawOrderImpl extends BService_BranchCompanyStaffWithdrawOrderImpl implements Service_BranchCompanyStaffWithdrawOrder {

	@Autowired private Service_BranchCompanyStaffWithdrawVerifyRecord service_BranchCompanyStaffWithdrawVerifyRecord;
	@Autowired private Service_BranchCompanyStaffMoneyRecord service_BranchCompanyStaffMoneyRecord;
	@Autowired private Service_Number service_Number;
	private String Number = "BranchCompanyStaffWithdrawOrderNumber";
	
	public TB_BranchCompanyStaffWithdrawOrder createInstance(TB_BranchCompanyStaff branchCompanyStaff, double amount, State_BranchCompanyStaffWithdrawOrder state){
		return dao.save(new TB_BranchCompanyStaffWithdrawOrder(
				new TB_BranchCompanyStaffWithdrawOrder.MustProperties() {
					@Override public String getNumber() {
						return service_Number.generateDateFormatNumber(Number);
					}
					@Override public Double getMoney() {
						return amount;
					}
					@Override public State_BranchCompanyStaffWithdrawOrder getState() {
						return state;
					}
					@Override public TB_BranchCompanyStaff getBranchCompanyStaff() {
						return branchCompanyStaff;
					}
				}, 
				new TB_BranchCompanyStaffWithdrawOrder.OptionalSingleProperties() {
					@Override public Date getSubmitDate() {
						return null;
					}
					@Override public Date getVerifyDate() {
						return null;
					}
					@Override public String getRealName() {
						return null;
					}
					@Override public String getAccountNumber() {
						return null;
					}
					@Override public String getBank() {
						return null;
					}
					@Override public String getVerifyComment() {
						return null;
					}
					@Override public String getRemitImgUrl() {
						return null;
					}
					@Override public TB_BranchCompanyStaff getVerifior() {
						return null;
					}
				}
			));
	}
	
	@Override
	public TB_BranchCompanyStaffWithdrawOrder vertifyPass(long id, TB_BranchCompanyStaff verifior) throws Exception {
		TB_BranchCompanyStaffWithdrawOrder order = findById(id);
		// 更新信息
		StateTransition<State_BranchCompanyStaffWithdrawOrder> trans = order.new UpdateProperties() {
			StateTransition<State_BranchCompanyStaffWithdrawOrder> trans;
			@Override public State_BranchCompanyStaffWithdrawOrder getState(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				trans = it.getState().t_verifyPass_from_Verifing();
				return trans.to();
			};
			@Override public Date getVerifyDate(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return new Date();
			};
			@Override public String getVerifyComment(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return null;
			};
			@Override public TB_BranchCompanyStaff getVerifior(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return verifior;
			};
		}.trans;
		// 记录
		service_BranchCompanyStaffWithdrawVerifyRecord.createPassRecord(order, trans.comment(), "");
		//
		return order;
	}

	@Override
	public TB_BranchCompanyStaffWithdrawOrder vertifyNoPass(long id, TB_BranchCompanyStaff verifior, String message) throws Exception {
		TB_BranchCompanyStaffWithdrawOrder order = findById(id);
		// 更新信息
		StateTransition<State_BranchCompanyStaffWithdrawOrder> trans = order.new UpdateProperties() {
			StateTransition<State_BranchCompanyStaffWithdrawOrder> trans;
			@Override public State_BranchCompanyStaffWithdrawOrder getState(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				trans = it.getState().t_verifyNoPass_from_Verifing();
				return trans.to();
			};
			@Override public Date getVerifyDate(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return new Date();
			};
			@Override public String getVerifyComment(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return message;
			};
			@Override public TB_BranchCompanyStaff getVerifior(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return verifior;
			};
		}.trans;
		// 记录
		service_BranchCompanyStaffWithdrawVerifyRecord.createNoPassRecord(order, trans.comment(), message);
		// 金额记录
		service_BranchCompanyStaffMoneyRecord.createReturn(order);
		//
		return order;
	}

	@Override
	public TB_BranchCompanyStaffWithdrawOrder create(TB_BranchCompanyStaff branchCompanyStaff, Double amount) throws Exception {
		StateTransition<State_BranchCompanyStaffWithdrawOrder> trans = State_BranchCompanyStaffWithdrawOrder.t_create();
		TB_BranchCompanyStaffWithdrawOrder order = createInstance(branchCompanyStaff, amount, trans.to());
		order.new UpdateProperties() {
			@Override public Date getSubmitDate(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return new Date();
			}
			@Override public String getRealName(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return branchCompanyStaff.getUser().getRealName();
			};
			@Override public String getAccountNumber(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return branchCompanyStaff.getUser().getAccountNumber();
			};
			@Override public String getBank(TB_BranchCompanyStaffWithdrawOrder it) throws Exception {
				return branchCompanyStaff.getUser().getBank();
			};
		};
		// 记录
		service_BranchCompanyStaffWithdrawVerifyRecord.createFlowRecord(order, trans.comment());
		// 金额记录
		service_BranchCompanyStaffMoneyRecord.create(order);
		//
		return order;
	}
	
	@Override
	public void setRemitImgUrl(long id, String remitImgUrl) {
		findById(id).setRemitImgUrl(remitImgUrl);		
	}
	
}
